package org.example.code.test2024.eleven;

import org.example.code.test2024.ten_mouth.ListNode;

public class test1111 {

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode sum = new ListNode();
        ListNode cur = sum;
        int count = 0;
        while(l1!=null||l2!=null){
            int num = count;
            if(l1!=null){
                num = num+l1.val;
                l1 = l1.next;
            }
            if(l2!=null){
                num = num+l2.val;
                l2 = l2.next;
            }
            if(num>=10){
                count = num/10;
                num = num%10;
            }else{
                count = 0;
            }
            cur.next = new ListNode(num);
            cur = cur.next;
        }
        if(count>0){
            cur.next = new ListNode(count);
        }
        return sum.next;
    }


    public ListNode swapPairs(ListNode head) {
        if(head==null){
            return null;
        }
        ListNode top = head.next;
        head.next = swapPairs(top.next);
        top.next = head;
        return top;
    }
}
